home *** CD-ROM | disk | FTP | other *** search
/ Windows 6-Pak - Disc 5 / Windows 6-Pak (InfoMagic) (Disc 5) (1999).ISO / C&C++Tools / sbparser.exe / cppb / SpeedTest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-01  |  4.1 KB  |  146 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "SpeedTest.h"
  6. #include "ParseDemo.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TFSpeedTest *FSpeedTest;
  11. //---------------------------------------------------------------------------
  12. __fastcall TFSpeedTest::TFSpeedTest(TComponent* Owner)
  13.     : TForm(Owner)
  14. {
  15. }
  16. //---------------------------------------------------------------------------
  17. void __fastcall TFSpeedTest::BExitClick(TObject *Sender)
  18. {
  19.     Close();
  20. }
  21. //---------------------------------------------------------------------------
  22.  
  23.  
  24. void __fastcall TFSpeedTest::FormShow(TObject *Sender)
  25. {
  26.     ETimes->SetFocus();
  27.     this->MFunction->Lines = FParser->MFunction->Lines;
  28.     EResult->Text = "no result ...";
  29.     LtheTime->Caption = "0";
  30. }
  31. //---------------------------------------------------------------------------
  32.  
  33. void __fastcall TFSpeedTest::BStartClick(TObject *Sender)
  34. {
  35.     int errPos;
  36.     long double times;
  37.     char tempstr[50];
  38.  
  39.     times = chartold(ETimes->Text.c_str(), &errPos);
  40.  
  41.     if ((errPos >= 0) || (times <= 0)) {
  42.         MessageBox(Handle, "This is a numerical field and has to be positive.",
  43.             "Error at 'How often?'",
  44.             MB_ICONERROR);
  45.         return;
  46.     }
  47.  
  48.     int BaseIn;
  49.     int BaseOut;
  50.     int AngularUnit;
  51.  
  52.     //Get data (Base for Input/output and angular unit) from the main form
  53.     FParser->GetBaseAndAngUnit(this, &BaseIn, &BaseOut, &AngularUnit);
  54.  
  55.     long double varValues[6];
  56.     bool err = false;
  57.  
  58.     //Get data (values of the variables) from the main form
  59.     err = FParser->GetVarValues(this, BaseIn, varValues);
  60.     if (err)
  61.         return;
  62.  
  63.     long double Result;
  64.     long double AddedResult = 0;
  65.     AnsiString funcStr = MFunction->Text.c_str();
  66.     long ctime = GetCurrentTime();
  67.  
  68.     Screen->Cursor = crHourGlass;
  69.        //Create an sbParser object and receive its HANDLE
  70.     HANDLE hParser = CreateNewParser(funcStr.c_str(), BaseIn, 6, "xyzuvw");
  71.     Screen->Cursor = crDefault;
  72.        if (GetIsError(hParser)) {
  73.         char errText[50];
  74.  
  75.         //An error has occurred (see documentation)
  76.         MessageBox(Handle, ldtochar(errText, GetGlobalError(hParser)),
  77.             "Errornumber in Function (see documentation)",
  78.             MB_ICONERROR);
  79.  
  80.            //Delete of the sbParser-object
  81.         DeleteParser(hParser);
  82.         return;
  83.     }
  84.        SetAngularUnitTo(hParser, AngularUnit);
  85.  
  86.     //Creation time
  87.     ctime = GetCurrentTime() - ctime;
  88.     LtheTime0->Caption = ldtochar(tempstr, (long double)ctime/1000, 12);
  89.  
  90.     //Reset time
  91.     ctime = GetCurrentTime();
  92.     Screen->Cursor = crHourGlass;
  93.     if (err) {
  94.         EResult->Text = "Error";
  95.         ctime = 0;
  96.     }
  97.     else
  98.     for (long iCount = 1; iCount <= times; iCount++) {
  99.         //Compute the result
  100.         AddedResult = AddedResult + GetResultExt(hParser, varValues);
  101.            if (GetIsError(hParser)) {
  102.             char errText[50];
  103.  
  104.             //An error has occurred (see documentation)
  105.             MessageBox(Handle, ldtochar(errText, GetGlobalError(hParser)),
  106.                 "Errornumber in Function (see documentation)",
  107.                 MB_ICONERROR);
  108.             err = true;
  109.             break;
  110.         }
  111.     }
  112.     Screen->Cursor = crDefault;
  113.  
  114.     if (err) {
  115.         EResult->Text = "Error";
  116.         ctime = 0;
  117.     }
  118.     else {
  119.         char tempstr[50];
  120.  
  121.         //Convert the long double to a string
  122.         ConvertToBase(tempstr,AddedResult,15,BaseOut);
  123.  
  124.         EResult->Text = tempstr;
  125.  
  126.         ctime = GetCurrentTime() - ctime;
  127.     }
  128.  
  129.     //Calculation time
  130.     LtheTime->Caption = ldtochar(tempstr, (long double)ctime/1000, 12);
  131.  
  132.        //Delete of the sbParser-object
  133.     DeleteParser(hParser);
  134. }
  135. //---------------------------------------------------------------------------
  136.  
  137. void __fastcall TFSpeedTest::ETimesChange(TObject *Sender)
  138. {
  139.     EResult->Text = "no result ...";
  140. }
  141. //---------------------------------------------------------------------------
  142.  
  143.  
  144.  
  145.  
  146.